home *** CD-ROM | disk | FTP | other *** search
/ Mac OS 9 Serial Number Archive / SN Archive 2023.11.04.toast / BSNG / SDK / BSNG SDK 2.6 / Contributed / Basic / Generate.c next >
Encoding:
C/C++ Source or Header  |  1998-08-22  |  6.0 KB  |  217 lines  |  [TEXT/CWIE]

  1. #include "BSNG API.h"
  2. #include "standard utils.h"
  3. #include "Generate.h"
  4.  
  5. /* these should be moved into standard utils.h */
  6. OSErr WriteData(BSNGParamBlockPtr inData, const char* inText, long inLength);
  7. OSErr WriteCString(BSNGParamBlockPtr inData, const char* inString);
  8. OSErr WritePString(BSNGParamBlockPtr inData, StringPtr inString);
  9.  
  10.  
  11. /* NOTE: anything between EXAMPLE BEGIN and EXAMPLE END may be safely deleted.
  12.    The rest of the framework, when left in place, will take care of all the
  13.    annoying details. */
  14.    
  15.    
  16.    
  17. /*
  18.  * UserCalculate:
  19.  * Calculate the serial number here.  If you get here, the input has already
  20.  * been validated with UserValidate.
  21.  */
  22.  
  23. short UserCalculate(BSNGParamBlockPtr inData)
  24. {
  25.     StringPtr        item1 = inData->itemValue[kItemValue1];
  26.     StringPtr        item2 = inData->itemValue[kItemValue2];
  27.     StringPtr        item3 = inData->itemValue[kItemValue3];
  28.     StringPtr        item4 = inData->itemValue[kItemValue4];
  29.     StringPtr        item5 = inData->itemValue[kItemValue5];
  30.     short       outIndex = -1;
  31.  
  32.   /* EXAMPLE BEGIN ===== */
  33.  
  34.     /* Calculate the SN. */
  35.     myCopyPStr("\p<result>", item4);
  36.  
  37.   /* Set the index of the result field, or leave it alone if you don't
  38.      want to alter the clipboard. */
  39.   outIndex = kItemValue4;
  40.  
  41.   /* EXAMPLE END ======= */
  42.     
  43.     return outIndex;
  44. }
  45.  
  46.  
  47.  
  48. /* 
  49.  * UserValidate:
  50.  * Check the entry fields to make sure their data is acceptable to the
  51.  * serial number algorithm.  Set (error) to true if there's something
  52.  * wrong with them.
  53.  */
  54.  
  55. Boolean UserValidate(BSNGParamBlockPtr inData)
  56. {
  57.     StringPtr        item1 = inData->itemValue[kItemValue1];
  58.     StringPtr        item2 = inData->itemValue[kItemValue2];
  59.     StringPtr        item3 = inData->itemValue[kItemValue3];
  60.     StringPtr        item4 = inData->itemValue[kItemValue4];
  61.     StringPtr        item5 = inData->itemValue[kItemValue5];
  62.     Boolean error = false;
  63.     
  64.   /* EXAMPLE BEGIN ===== */
  65.  
  66.     /* We do some simple checks here if the edit fields are not empty or not
  67.        longer than 8 characters, additionally we could also check if the values
  68.        are really only numbers, but I skipped that because the input filter for
  69.        the edit fields was set to integer anyway (defined in Constructor) */
  70.     
  71.     if ((item2[0] < 1) || (item2[0] > 8))
  72.     {
  73.       /* Tell BSNG which field had the error in it. */
  74.       
  75.         inData->errorInItem = kEditItem2;
  76.         error = true;
  77.         
  78.         /* Setting errorText to anything other than empty causes an error dialog
  79.            to pop up with the specified error text.  Leaving it empty and returning
  80.            and error just makes BSNG beep. */
  81.            
  82.         myAppendPStr(inData->errorText, "\pEditField 2 contains a wrong value");
  83.     }
  84.  
  85.   /* EXAMPLE END ======= */
  86.  
  87.     if (error)
  88.     {
  89.         return (false);    
  90.     }
  91.  
  92.     return (true);
  93. }
  94.  
  95.  
  96.  
  97. /*
  98.  * UserFillDefaults:
  99.  * Initialize the EditFields with initial default values (optional, they are
  100.  * empty otherwise) if you create a name-based generator please make sure
  101.  * that you copy the name, company and/or numCopies values into the
  102.  * corresponding fields
  103.  */
  104.  
  105. void UserFillDefaults(BSNGParamBlockPtr inData)
  106. {
  107.     StringPtr        item1 = inData->itemValue[kItemValue1];
  108.     StringPtr        item2 = inData->itemValue[kItemValue2];
  109.     StringPtr        item3 = inData->itemValue[kItemValue3];
  110.     StringPtr        item4 = inData->itemValue[kItemValue4];
  111.     StringPtr        item5 = inData->itemValue[kItemValue5];
  112.  
  113.   /* EXAMPLE BEGIN ===== */
  114.  
  115.   /* In this example we fill out the default (preferences) values.  You
  116.      can fill the fields out however you like. */
  117.  
  118.     myCopyPStr(inData->name, item1);
  119.     myCopyPStr(inData->company, item2);
  120.     myCopyPStr(inData->numCopies, item3);
  121.     myCopyPStr("\p", item4);
  122.  
  123.   /* EXAMPLE END ======= */
  124. }
  125.  
  126.  
  127.  
  128. /*
  129.  * UserWriteListHeader:
  130.  * This comes after the program name.  If you want to write something only
  131.  * once rather than (numOfListNumbers) times, do it here.
  132.  */
  133.  
  134. OSErr UserWriteListHeader(BSNGParamBlockPtr inData)
  135. {
  136.     StringPtr        item1 = inData->itemValue[kItemValue1];
  137.     StringPtr        item2 = inData->itemValue[kItemValue2];
  138.     StringPtr        item3 = inData->itemValue[kItemValue3];
  139.     StringPtr        item4 = inData->itemValue[kItemValue4];
  140.     StringPtr        item5 = inData->itemValue[kItemValue5];
  141.     
  142.   /* EXAMPLE BEGIN ===== */
  143.  
  144.   if (WritePString(inData, "\pName:    ")   != noErr) goto failed;
  145.     if (WritePString(inData, item1)           != noErr) goto failed;
  146.     if (WritePString(inData, "\p\rCompany: ") != noErr) goto failed;
  147.     if (WritePString(inData, item2)           != noErr) goto failed;
  148.     if (WritePString(inData, "\p\rCopies:  ") != noErr) goto failed;
  149.     if (WritePString(inData, item3)           != noErr) goto failed;
  150.     if (WriteCString(inData, "\r")            != noErr) goto failed;
  151.  
  152.   /* EXAMPLE END ======= */
  153.  
  154.     return noErr;
  155.     
  156. failed:
  157.     return ioErr;
  158. }
  159.  
  160.  
  161.  
  162. /*
  163.  * UserWriteListNumber:
  164.  * This comes after the header created by UserWriteListHeader. The serial
  165.  * number has already been generated and now we just need to write the
  166.  * results to file.
  167.  */
  168.  
  169. OSErr UserWriteListNumber(BSNGParamBlockPtr inData)
  170. {
  171.     StringPtr        item1 = inData->itemValue[kItemValue1];
  172.     StringPtr        item2 = inData->itemValue[kItemValue2];
  173.     StringPtr        item3 = inData->itemValue[kItemValue3];
  174.     StringPtr        item4 = inData->itemValue[kItemValue4];
  175.     StringPtr        item5 = inData->itemValue[kItemValue5];
  176.  
  177.   /* EXAMPLE BEGIN ===== */
  178.  
  179.   if (WritePString(inData, "\pSerial:  ") != noErr) goto failed;
  180.   if (WritePString(inData, item4)         != noErr) goto failed;
  181.   if (WriteCString(inData, "\r")          != noErr) goto failed;
  182.  
  183.   /* EXAMPLE END ======= */
  184.  
  185.     return noErr;
  186.     
  187. failed:
  188.     return ioErr;
  189. }
  190.  
  191.  
  192.  
  193. /*
  194.  * UserRandomize:
  195.  * Do whatever randomization you want to do; shuffle entry fields, etc.
  196.  * Anything that gets randomized should get written by UserWriteListNumber
  197.  * rather than UserWriteListHeader.
  198.  */
  199.  
  200. void UserRandomize(BSNGParamBlockPtr inData)
  201. {
  202.     StringPtr        item1 = inData->itemValue[kItemValue1];
  203.     StringPtr        item2 = inData->itemValue[kItemValue2];
  204.     StringPtr        item3 = inData->itemValue[kItemValue3];
  205.     StringPtr        item4 = inData->itemValue[kItemValue4];
  206.     StringPtr        item5 = inData->itemValue[kItemValue5];
  207.  
  208.   /* EXAMPLE BEGIN ===== */
  209.   
  210.   /* This really needs no example. Mess with the item text if necessary.
  211.      mess with internal global data if necessary. */
  212.   
  213.   /* EXAMPLE END ======= */
  214. }
  215.  
  216.  
  217.